package com.example.beat_x3.Adapter;

import android.annotation.SuppressLint;

import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.view.LayoutInflater;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.beat_x3.R;

import java.util.ArrayList;

import Entity.Inf;
import Entity.Reservation;

public class HomeAdapter extends RecyclerView.Adapter<HomeAdapter.Holder> {
    public ArrayList<Reservation> reservations;

    @NonNull
    @Override
    public HomeAdapter.Holder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new Holder(LayoutInflater.from(Inf.context).inflate(R.layout.item_home, parent, false));
    }

    @Override
    public void onBindViewHolder(@NonNull Holder holder, int position) {
        holder.bind(position);
    }

    @SuppressLint("NotifyDataSetChanged")
    public void refresh() {
        if (reservations != null)
            notifyDataSetChanged();
    }

    @Override
    public int getItemCount() {
        if (reservations == null) return 0;
        return reservations.size();
    }

    class Holder extends RecyclerView.ViewHolder {
        TextView wenben1, wenben2, wenben3, wenben4;
        String appointmentNumber;

        public Holder(@NonNull View itemView) {
            super(itemView);
            this.wenben2 = itemView.findViewById(R.id.myr_text2);
            this.wenben3 = itemView.findViewById(R.id.myr_text3);
            this.wenben4 = itemView.findViewById(R.id.myr_text4);
            this.wenben1 = itemView.findViewById(R.id.myr_text5);
        }

        @SuppressLint("SetTextI18n")
        void bind(int position) {
            appointmentNumber = reservations.get(position).AppointmentNumber;
            wenben3.setText("地点:" + reservations.get(position).PlacePosition);
            wenben2.setText(reservations.get(position).ActivityType);
            wenben4.setText("演出时间:" + reservations.get(position).AppointmentTime);
            wenben1.setText("发起者:" + reservations.get(position).StudentAccount);

        }
    }
}

